package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:等待线程结束
 * User: bjc
 * Date: 2025-08-15
 * Time: 21:20
 */
public class ThreadDemo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("这是一个线程t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程t执行结束");
        });
        t.start();
        //线程等待
        //因为是在main线程调用，所以main线程等待t线程结束，之后在执行main线程代码
        t.join();
        System.out.println(Thread.currentThread().isInterrupted());
        System.out.println("主线程main，期望是在t线程结束后打印");


    }
}
